# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def generate_random_story
    stories = Story.find(:all)
    stories[rand(stories.length)]
  end

  def snippet(summary)
    wordcount = 30
    summary.split[0..(wordcount-1)].join(" ") + (summary.split.size > wordcount ? "..." : "")
  end
  
  def user_count
    User.find(:all).length
  end

  def story_count
    Story.find(:all).length
  end
  
  def most_recently_update_story
    Line.find(:last)
  end
  
  def find_six_highly_rated_stories
    Story.find_all_by_rating(3..5).sort_by{ rand }.slice(0...6)
  end
  
end
